// 机构信息查询页面
<template>
  <el-main>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column label="机构信息查询">
        <el-table-column type="index" label="序号" width="60">
        </el-table-column>
        <el-table-column prop="instId" label="机构编号"></el-table-column>
        <el-table-column prop="instName" label="机构名称"> </el-table-column>
        <el-table-column prop="createDate" label="创建日期"> </el-table-column>
        <el-table-column prop="legalRep" label="法定代表人"> </el-table-column>
        <el-table-column label="操作" width="100">
          <!-- <el-button type="text" size="small" @click="deleteInfo()">删除</el-button> -->
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>
    <div style="display: flex; justify-content: center;">
      <el-button style="width: 100%" size="small" @click="add()">新增</el-button>
    </div>
  </el-main>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          instId: "",
          instRole: "",
          createDate: "",
          legalRep: "",
        },
      ],
      instLastId: "",
    };
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index);
      console.log(row.instId);
      let id = row.instId;
      this.$axios({
        method: "delete",
        url: `http://localhost:8001/institution/deleteInst?instId=${id}`,
      })
        .then((result) => {
          console.log(result);
          console.log("请求删除机构信息成功！");
          this.getDetailedInfo();
        })
        .catch((err) => {
          console.log("请求删除机构信息失败！" + err);
        });
    },
    // 请求机构信息
    getDetailedInfo() {
      this.$axios({
        method: "get",
        url: `http://localhost:8001/institution/getAll`,
      })
        .then((result) => {
          console.log(result.data.data.content);
          console.log("请求机构信息成功！");
          this.tableData = result.data.data.content;

          // console.log(result.data.data.content[result.data.data.content.length -1].instId);
        })
        .catch((err) => {
          console.log("请求机构信息失败！" + err);
        });
    },

    // 新增按钮
    // 跳转到详细信息编辑页面DetailedInfo.Vue
    // 查询数据库机构编号信息自动生成新增的编号
    add() {
      this.$router.replace("/detailedInfo");
    },
    // 删除方法网络请求
    deletehttp() {
      this.$axios({
        method: "get",
        url: "http://localhost:8001/institution/deleteInst",
      })
        .then((result) => {
          console.log("请求删除机构信息成功！");
        })
        .catch((err) => {
          console.log("请求删除机构信息失败！" + err);
        });
    },
  },
  created() {
    this.getDetailedInfo();
  },
};
</script>

<style>
</style>